package com.compayname.projectname.base.data;

import java.io.Serializable;

public class ViewData<T> implements Serializable {

    private static final long serialVersionUID = 7408790903212368997L;

    private Integer code = 1;

    private String message;

    private T data;

    public ViewData(){}

    public ViewData(T obj) {
        this.data = obj;
    }

    public ViewData(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public ViewData(Integer code, String message, T obj) {
        this.code = code;
        this.message = message;
        this.data = obj;
    }

    public static <T> ViewData<T> ok() {
        return new ViewData<>();
    }

    public static <T> ViewData<T> ok(T obj) {
        return new ViewData<>(obj);
    }

    public static <T> ViewData<T> error(String msg) {
        return new ViewData<>(-1, msg);
    }

    public static <T> ViewData<T> error(Integer code, String msg) {
        return new ViewData<>(code, msg);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "ViewData{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
